import { usePageRequest } from "../../../../utils/request";
import dayjs from "../../../../utils/day";

Component({
    properties: {},
    data: {},
    methods: {
        onLoad() {
            this.allRequest = new usePageRequest('api/allwalletlist', {
                pretreatment: data => {
                    data.list = data.list.map(month => {
                        month.details = month.details.map(item => {
                            item.create_time = dayjs.unix(item.create_time).format('YYYY-MM-DD HH:mm')
                            return item
                        })
                        return month
                    })
                    return data
                }
            }, this)
            this.inRequest = new usePageRequest('api/incomewalletlist', { hold: true }, this)
            this.outRequest = new usePageRequest('api/expendwalletlist', { hold: true }, this)
        },
        changeStatus(e) {
            const index = Number(e.detail.index)
            this.setData({
                status: index
            })
            wx.startPullDownRefresh()
        },
        onPullDownRefresh() {
            switch (this.data.status) {
                case 0:
                    this.allRequest.reset().then(wx.stopPullDownRefresh)
                    break;
                case 1:
                    this.inRequest.reset().then(wx.stopPullDownRefresh)
                    break;
                case 2:
                    this.outRequest.reset().then(wx.stopPullDownRefresh)
            }
        },
        onReachBottom() {
            switch (this.data.status) {
                case 0:
                    this.allRequest.next()
                    break;
                case 1:
                    this.inRequest.next()
                    break;
                case 2:
                    this.outRequest.next()
            }
        }
    }
});
